Back to course home
0% completed
Vote For New Content
Meta Hard Problems
Sliding Window Median (hard)
Solution: Sliding Window Median
Alien Dictionary (hard)
Solution: Alien Dictionary
Minimum Window Substring (hard)
Solution: Minimum Window Substring
Best Meeting Point (hard)
Solution: Best Meeting Point
Maximum Sum of 3 Non-Overlapping Subarrays (hard)
Solution: Maximum Sum of 3 Non-Overlapping Subarrays
Making A Large Island (hard)
Solution: Making A Large Island
Basic Calculator (Hard)
Solution: Basic Calculator
Serialize and Deserialize Binary Tree (hard)
Solution: Serialize and Deserialize Binary Tree
Longest Increasing Path in a Matrix (hard)
Solution: Longest Increasing Path in a Matrix
Valid Palindrome III (hard)
Solution: Valid Palindrome III
Contiguous Array (medium)
Problem Statement
Given an array nums containing only 1 and 0 digits, return the maximum length of the contiguous subarray having an equal number of 1 and 0.
Examples
- Example 1:
- Input:
[0, 1] - Expected Output:
2 - Justification: The longest subarray with equal numbers of 0s and 1s is [0, 1].
- Input:
- Example 2:
- Input:
[1, 1, 0, 0, 1, 1, 0] - Expected Output:
6 - Justification: The subarray [1, 0, 0, 1, 1, 0] contains three 0s and three 1s.
- Input:
- Example 3:
- Input:
[0, 1, 1, 0, 1, 0, 0, 1, 1] - Expected Output:
8 - Justification: The subarray from the first to the eighth element is the longest with an equal number of 0s and 1s.
- Input:
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Count and Say
Solution: Contiguous Array
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself